package day14_io.demo06_Buffered字符缓冲流;

import java.io.*;
//字符缓冲流复制资源
public class Demo05_字符缓冲流复制 {
    public static void main(String[] args) throws Exception {
        File file = new File("E:\\csw\\Demo\\csw1");
        File newfile = new File("E:\\csw\\Demo\\copy");
        show(file, newfile);
    }

    public static void show(File file, File newfile) throws Exception {
        File[] files = file.listFiles();
        for (File file1 : files)
            if (file1.isFile()) {
                File file2 = new File(newfile, file1.getName());
                BufferedWriter bw = new BufferedWriter(new FileWriter(file2));
                BufferedReader br = new BufferedReader(new FileReader(file1.getAbsoluteFile()));
//                char[] chars = new char[1024];
                String s;
                while ((s=br.readLine())!=null){
                    bw.write(s);
                }
                bw.close();
                br.close();
            } else {
                File file2 = new File(newfile,file1.getName());
                file2.mkdirs();
                show(file1,file2);
            }
    }
}